﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    using DAL.Entities;

    public class SanXuatDAL : BaseDAL, UTL.IBaseDAL
    {
        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            string sql = @" select * from SANXUAT a join SANPHAM b on a.MASP=b.MASP join DN c on a.MSDN=c.MSDN join GPSX d on  a.SOGP=d.SOGP ";
            return ExecuteQuery(sql);
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            throw new NotImplementedException();
        }

        public bool Insert(object obj)
        {
            var o = (sanxuat)obj;
            string sql = @"set dateformat mdy; INSERT INTO sanxuat(msdn,masp,ngaybatdau,ngayketthuc,soluong,sogp) VALUES('{0}','{1}','{2}','{3}',{4},'{5}') ";
            sql = string.Format(sql, o.madn, o.masp, o.ngaydb, o.ngaykt, o.sl, o.sogp);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (sanxuat)obj;
            string sql = @"set dateformat mdy; UPDATE sanxuat SET soluong={0},ngayketthuc='{1}',sogp='{5}' wHERE msdn='{2}' and masp='{3}' and ngaybatdau='{4}' ";
            sql = string.Format(sql, o.sl,o.ngaykt,o.madn,o.masp,o.ngaydb,o.sogp);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            throw new NotImplementedException();
        }

        public bool deleteobj(object obj)
        {
            var o = (sanxuat)obj;
            string sql = @"set dateformat mdy;DELETE FROM sanxuat WHERE msdn = '{0}' and masp='{1}' and ngaybatdau='{2}' ";
            sql = string.Format(sql, o.madn, o.masp,o.ngaydb);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }


        public DataTable select_sp()
        {
            string sql = @"select masp as id,tensp as ten from sanpham";
            return ExecuteQuery(sql);
        }

        public DataTable select_dn()
        {
            string sql = @"select msdn as id,tendn as ten from dn";
            return ExecuteQuery(sql);
        }
        public DataTable select_giayphep()
        {
            string sql = @"select sogp as id,noidung as ten from gpsx ";
            return ExecuteQuery(sql);
        }

    }
}
